<?php
session_start();
if(isset($_POST['submit']))
{
 foreach($_POST['qty'] as $key=>$value)
 {
  if( ($value == 0) and (is_numeric($value)))
  {
   unset ($_SESSION['DT'][$key]);
  }
  elseif(($value > 0) and (is_numeric($value)))
  {
   $_SESSION['DT'][$key]=$value;
  }
 }
 header("location:DT.php");
}
?>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Shop UIT - Website bán điện thoại di động</title>
 <link rel="stylesheet" href="CSS/style1.css" />
 <link rel="stylesheet" type="text/css" href="CSS/Style.css">
</head>
<body background="index/bg.jpg">
<script language=javascript >

title_tmp1=document.title
if (title_tmp1.indexOf(">>")!=-1){
title_tmp2=title_tmp1.split(">>");
title_last="*~*"+title_tmp2[1];
title_last=title_last + "*~*" + title_tmp2[2];
}else{

if (title_tmp1.indexOf("*~*")!=-1){
title_tmp2=title_tmp1.split("*~*");
title_last="*~*"+title_tmp2[1];
if (title_last=="*~*"){title_last="*~*"};
if (title_last=="*~*"){title_last="*~*"};
}
else { title_last=" -- UIT Shop -- "}
}


title_new=""+title_last+""
step=0

function flash_title()
{
step++
if (step==8) {step=1}
if (step==1) {document.title='[----*'+title_new+'*----]'}
if (step==2) {document.title='[---*-'+title_new+'-*---]'}
if (step==3) {document.title='[--*--'+title_new+'--*--]'}
if (step==4) {document.title='[-*---'+title_new+'---*-]'}
if (step==5) {document.title='[--*--'+title_new+'--*--]'}
if (step==6) {document.title='[---*-'+title_new+'-*---]'}
if (step==7) {document.title='[----*'+title_new+'*----]'}
setTimeout("flash_title()",180);
}
flash_title()

</script>
<div id="divContainer">
  <div id="divHeader">
			<div id="divBanner">
			<embed src="flash/banner.swf" quality="high" type="application/x-shockwave-flash" wmode="transparent" width="1024" height="220" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always"></embed>
			</div>
			<div id="divMenu">
	<ul>
			<li><a href="http://localhost/WebDTDD/" class="active" title="Trang chủ"><b>Trang Chủ</b></a></li>
            <li><a href="http://localhost/WebDTDD/gioithieu.php" title="Giới thiệu"><b>Giới thiệu</b></a></li>
            <li><a href="http://localhost/WebDTDD/sanpham.php" title="Sản phẩm"><b>Sản Phẩm</b></a></li>
			<li><a href="http://localhost/WebDTDD/dichvu.php" title="Dịch vụ"><b>Dịch vụ</b></a></li>
            <li><a href="http://localhost/WebDTDD/bando.php" title="Bản đồ"><b>Bản đồ</b></a></li> 
            <li><a href="http://localhost/WebDTDD/lienhe.php" title="Liên hệ"><b>Liên hệ</b></a></li>
					
			<span style="float: right; padding-left:50px; padding-bottom: 7px;">
			<input type="text" name="txtWord" />
			<input type="submit" value="Tìm kiếm" name="btnSearch" />
			<img src="index/shopping_cart.png" width="25" height="25" style='vertical-align: auto'>
            <?php
			 $ok=1;
 if(isset($_SESSION['DT']))
 {
  foreach($_SESSION['DT'] as $k=>$v)
  {
   if(isset($v))
   {
   $ok=2;
   }
  }
 }
 if ($ok != 2)
  {
  echo '<font size="2" color="#CCFF00" > 0 </font>';
 } else {
  $items = $_SESSION['DT'];
  echo '<font size="2" color="#CCFF00" ><a href="DT.php">'.count($items).'</a></font>';
 }?>
			</span>
						      
  </ul>
</ul>
  
    </div>
  </div>
			
		<div class="clr"></div>
		
		
		
  <div id="divLeft">
    <img src ="./DT/left.jpg"></br>
                
  </div>
    <div id="divRight">
   <img src ="./DT/right.jpg" width="202" ></br>
    </div>
        <div id = "divMid">
        <center>
<font color="#CCFF00"> <br><h1>GIỎ HÀNG CỦA BẠN</h1></font>
<?php
$ok=1;
if(isset($_SESSION['DT']))
{
 foreach($_SESSION['DT'] as $k => $v)
 {
  if(isset($k))
  {
   $ok=2;
  }
 }
}
if($ok == 2)
{

   echo "<form action='DT.php' method='post'>";
   foreach($_SESSION['DT'] as $key=>$value)
   {
    $item[]=$key;
   }
   $str=implode(",",$item);
   $connect=mysql_connect("localhost","root","") or die("Can not connect database");
   mysql_select_db("dtdd",$connect);
   
   $query=mysql_query("select * from sanpham where MaSP in ($str)");
   $total = "";
   $id = "";
   while($row=mysql_fetch_array($query))
   {
	   $id  = $row[0];
   echo "<div class='pro'>";
   echo "<h3>$row[2]</h3><br />";
   echo "<img src ='$row[5]' width='130px' height='160px'<br /><br /><br />";
   echo "<p align='right'><h4>Đơn Giá: ". number_format($row[4],3) ." VND</h4></p><br />";
   echo "<p align='right'><h4>Số Lượng: <input type='text' name='qty[$id]' size='5' value='{$_SESSION['DT'][$id]}'> - ";
   echo "<a href='delDT.php?productid=$row[0]'>Xóa món hàng</a></h4></p><br />";
   echo "<p align='right'> <h4>Giá tiền cho món hàng: ". number_format($_SESSION['DT'][$row[0]]*$row[4],3)." VND</h4></p>";
   echo "</div>";
   
   $total+=$_SESSION['DT'][$row[0]]*$row[4];
   }
  echo "<div class='pro' align='right'>";
  echo "<b><h3>Tổng tiền thanh toán : <font color='red'>". number_format($total,3)." VND</font></h3></b>";
  echo "</div>";
  echo "<input type='submit' name='submit' value='Cập nhật giỏ hàng'> </font>";
  echo "<div class='pro' align='center'>";
  echo "<b><a href='index.php'>Tiếp tục chọn hàng</a> - <a href='delDT.php?productid=0'>Xóa bỏ giỏ hàng</a></b>";
  echo "</div>"; 
 }
else
 {
  echo "<div class='pro'>";
  echo "<p align='center'>Bạn không có món hàng nào trong giỏ hàng !!! <br /><a href='index.php'>Mời bạn chọn điện thoại</a></p>";
  echo "</div>";
 }

?>
</center>
</div>
		<div class="clr"></div>
		<div id="divFooter">Footer
		</div>
</div>
</body>
</html>

